<template>
    <div>
		<div>
			<el-input placeholder="员工姓名关键字" prefix-icon="el-icon-search"
			          clearable
			          @clear="initEmps"
			          style="width: 150px;margin-right: 10px" v-model.trim="keyword"
			          @keydown.enter.native="initEmps"></el-input>
					<span style="margin-left: 300px;">时间：</span>
			  <el-date-picker
			 style="width: 120px;"
			    v-model="time"
			    type="month"
			    placeholder="选择月"
				format="yyyy-MM"
				value-format="yyyy-MM"
				@change="initEmps">
			  </el-date-picker>
			  <span >员工工资表</span>
		</div>
        <div>
            <el-table :data="emps" border stripe size="mini">
                <el-table-column type="selection" align="left" width="55"></el-table-column>
                <el-table-column prop="employee.name" label="姓名" fixed width="120" align="left"></el-table-column>
                <el-table-column prop="employee.workId" label="工号" width="120" align="left"></el-table-column>
                <el-table-column prop="payDate" label="月份" width="200" align="left"></el-table-column>
                <el-table-column prop="payNumber" label="工资" width="120" align="left"></el-table-column>
                <el-table-column label="具体工资" align="center">
                    <template slot-scope="scope">
                        <el-tooltip placement="right" v-if="scope.row.employeeSalary.salary">
                            <div slot="content">
                                <table>
                                    <tr>
                                        <td>基本工资</td>
                                        <td>{{scope.row.employeeSalary.salary.basicSalary}}</td>
                                    </tr>
									<tr>
										<td></td>
									    <td>+</td>
									</tr>
                                    <tr>
                                        <td>交通补助</td>
                                        <td>{{scope.row.employeeSalary.salary.trafficSalary}}</td>
                                    </tr>
									<tr>
										<td></td>
									    <td>+</td>
									</tr>
                                    <tr>
                                        <td>午餐补助</td>
                                        <td>{{scope.row.employeeSalary.salary.lunchSalary}}</td>
                                    </tr>
									<tr>
										<td></td>
									    <td>+</td>
									</tr>
                                    <tr>
                                        <td>奖金</td>
                                        <td>{{scope.row.employeeSalary.salary.bonus}}</td>
                                    </tr>
                                </table>
                            </div>
                            <el-tag>{{scope.row.employeeSalary.salary.name}}</el-tag>
                        </el-tooltip>
                        <el-tag v-else>暂未设置</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-popover
                                placement="left"
                                title="修改工资账套"
                                @show="showPop(scope.row.salary)"
                                @hide="hidePop(scope.row)"
                                width="200"
                                trigger="click">
                            <div>
                                <el-select v-model="currentSalary" placeholder="请选择" size="mini">
                                    <el-option
                                            v-for="item in salaries"
                                            :key="item.id"
                                            :label="item.name"
                                            :value="item.id">
                                    </el-option>
                                </el-select>
                            </div>
                            <el-button slot="reference" type="danger">修改工资账套</el-button>
                        </el-popover>
                    </template>
                </el-table-column>
            </el-table>
            <div style="display: flex;justify-content: flex-end">
                <el-pagination
                        background
                        @size-change="sizeChange"
                        @current-change="currentChange"
                        layout="sizes, prev, pager, next, jumper, ->, total, slot"
                        :total="total">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "SalSobCC",
        data() {
            return {
                emps: [],
                total: 0,
                currentPage: 1,
                currentSize: 10,
                currentSalary: null,
                salaries: [],
				keyword:'',
				time: ''
            }
        },
        mounted() {
			this.getNowDate();
            this.initEmps();
            this.initSalaries();
        },
        methods: {
            sizeChange(size) {
                this.currentSize = size;
                this.initEmps();
            },
            currentChange(page) {
                this.currentPage = page;
                this.initEmps();
            },
            hidePop(data) {
                if (this.currentSalary) {
                    this.putRequest('/employeesalary/update/?employeeId=' + data.id + '&salaryId=' + this.currentSalary).then(resp => {
                        if (resp) {
                            this.initEmps()
                        }
                    });
                }
            },
            showPop(data) {
                if (data) {
                    this.currentSalary = data.id;
                } else {
                    this.currentSalary = null;
                }
            },
            initSalaries() {
           
            },
			getNowDate() {
			    let date = new Date();
			    let y = date.getFullYear();
			    let m = date.getMonth() + 1;
			          m = m < 10 ? "0" + m : m;
			          this.time= y + "-" + m ;
			},
            initEmps() {
				console.log(this.time);
                this.getRequest("/paysalary/get/?page=" + this.currentPage + '&size=' + this.currentSize +'&payDate='+this.time+'&name='+this.keyword).then(resp => {
					if (resp) {
						console.log(resp);
                        this.emps = resp.object.list;
                        this.total = resp.object.total;
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>